package main

import "fmt"

func assert(b bool, msg string) {
    if (!b) {
        panic(msg)
    }
}

func test1() {
    fmt.Println("run test1")

    colors := make(map[string]string)
    colors["Red"] = "#da1337"

    colors2 := map[string]string {
        "AliceBlue": "#f0f8ff",
        "Coral": "#ff7f50",
        "DarkGray": "#a9a9a9",
        "ForestGreen": "#228b22",
    }

    assert(len(colors2) == 4, "")

    _, exist := colors["Red"]
    assert(exist, "Red not exist")
    _, exist2 := colors2["Blue"]
    assert(!exist2, "Blue exist")

    colors3 := make(map[string]string)
    for k, v := range(colors2) {
        colors3[k] = v
    }
    assert(len(colors3) == 4, "")

    delete(colors3, "AliceBlue")
    assert(len(colors3) == 3, "")
    _, exist3 := colors3["AliceBlue"]
    assert(!exist3, "AliceBlue exist")

    var colors4 map[string]string
    assert(colors4 == nil, "")
    // colors4["error"] = "error" // error
}

func remove_color(colors map[string]string, key string) map[string]string {
    delete(colors, key)
    return colors
}

func test2() {
    fmt.Println("run test2")

    colors := map[string]string {
        "AliceBlue": "#f0f8ff",
        "Coral": "#ff7f50",
        "DarkGray": "#a9a9a9",
        "ForestGreen": "#228b22",
    }

    assert(len(colors) == 4, "")
    _, exist := colors["AliceBlue"]
    assert(exist, "AliceBlue not exist")

    colors2 := remove_color(colors, "AliceBlue")
    _, exist2 := colors2["AliceBlue"]
    assert(!exist2, "AliceBlue exist")

    _, exist3 := colors["AliceBlue"]
    assert(!exist3, "AliceBlue exist")
}

func main() {
    test1()
    test2()
}
